#主函数
def main():
    s = input("请输入字符串:")
    print(s)
    if len(s) == 0 or len(s) > 255:
        print("输入的字符串不合法")
    s1 = list(filter(lambda char: char.isalpha(), s))
    print("去除非英文字符后的密文为：{}".format(s1))
    s2 = revese(s1)
    print("反转后的密文为：{}".format(s2))
    s3 = enCode(s2)
    print("加密后的密文为：{}".format(s3))
#反转密文
def revese(s1):
    new_string = []
    index = len(s1)
    while index:
        index -= 1
        new_string += s1[index]
    return new_string
#加密密文
def enCode(s2):
    k = 4
    str_list = s2
    str_list_encry = str_list
    i = 0
    while i < len(str_list):
        if ord(str_list[i]) < 123-k:
            str_list_encry[i] = chr(ord(str_list[i]) + k)
        else:
            str_list_encry[i] = chr(ord(str_list[i]) + k - 26)
        i = i+1
    return str_list_encry
main()



